<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../../../views/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>专家字典表</title>
<head>
    <meta charset="utf-8">
    <title>专家字典表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="/fdoctor-ms/statics/beginnerAdmin/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/fdoctor-ms/statics/beginnerAdmin/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/fdoctor-ms/statics/beginnerAdmin/css/btable.css" />
    
    <script type="text/javascript" src="/fdoctor-ms/statics/beginnerAdmin/plugins/layui/layui.js"></script>
    <script type="text/javascript" src="/fdoctor-ms/statics/js/jquery-2.1.4.min.js"></script>
    
</head>

<body style=" background-color: gainsboro;">

    <div style="margin:0px; background-color: white;">
        <blockquote class="layui-elem-quote">
        <form class="layui-form" action="">
        	<div class="layui-form-item" align="left" style="margin-left: 0px;margin-top: 10px;">
			  	<div class="layui-inline"  >
			  	<label class="layui-form-label" > 医院：</label>
			    <div class="layui-input-inline" ">
			      	<select name="orgId" id="orgId" lay-search>
						<option value="" style="width: 190px;">可输入医院名搜索</option>
						<option value="0" >全部</option>
							<c:forEach items="${hospitalList}" var="hospitalItem">
								<option value="${hospitalItem.id}">${hospitalItem.orgName}</option>
							</c:forEach>
					</select>  
			    </div>
			  	</div>
			  	
			    <div class="layui-inline" >
				<label class="layui-form-label"  >医生姓名：</label>
					<div class="layui-input-inline" >
		      		<input name="expertName"  class="layui-input"  id="expertName" style="width: 190px;">
					</div>
				</div>
				
			    
			    <div class="layui-inline" >
			    	 <div class="layui-input-inline">
			    	<button class="layui-btn layui-btn-radius" style="width: 150px;margin-left: 50px;" id="selectButton" type="button">查询</button>
			    	</div>
			    </div>
			    
			 </div>
			</form>
        </blockquote>
		<div class="layui-btn-group">
		<c:if test="${fn:length(sessionScope.user_in_session.orgIds)> 1}">  
		  <button class="layui-btn layui-btn-primary layui-btn-small" id="addButton"><i class="layui-icon">&#xe654;</i>新增专家</button>
		  <button class="layui-btn layui-btn-primary layui-btn-small" id="updateButton"><i class="layui-icon">&#xe642;</i>编辑该专家</button>
		  <!-- <button class="layui-btn layui-btn-primary layui-btn-small" id="deleteButton"><i class="layui-icon">&#xe640;</i>删除该专家</button> -->
		</c:if> 
		  <button class="layui-btn layui-btn-primary layui-btn-small" id="detailButton" ><i class="layui-icon">&#xe60a;</i>该专家详情</button>
		</div>
        <div id="content" style="width: 100%;height: 500px;"></div>
    </div>

    <script>
    
    	function tableConfig(){
    		layui.config({
                base: '/fdoctor-ms/statics/beginnerAdmin/js/'
            }).use(['btable','layer'], function () {
                var layer = layui.layer;
                
                var btable = layui.btable(),
                    $ = layui.jquery;
                
                //layer.config({
                	//id : Math.ceil(100)	//防止重复弹窗
                //});
                btable.set({
                    elem: '#content',
                    url: '/fdoctor-ms/expert/getExpertList',
                    type: 'GET',
                    pageSize: 15,
                    columns: [{
                        fieldName: '专家id',
                        field: 'id',
                        hidden: true
                    },{
                        fieldName: '专家账号id',
                        field: 'expertAccountId',
                        hidden: true
                    },{
                        fieldName: '专家身份证',
                        field: 'idCard'
                    },{
                        fieldName: '医院',
                        field: 'orgId',
                        colRender : 'typeRenderD'
                    },{
                        fieldName: '姓名',
                        field: 'expertName'
                    },{
                        fieldName: '账号',
                        field: 'userName'
                    },{
                        fieldName: '性别',
                        field: 'sex',
                        colRender : 'typeRenderA'
                    },{
                        fieldName: '所在科室',
                        field: 'department',
                        colRender : 'typeRenderC'
                    },{
                        fieldName: '职称',
                        field: 'title',
                        colRender : 'typeRenderC'
                    },{
                        fieldName: '电话',
                        field: 'phoneNumber',
                        colRender : 'typeRenderC'
                    }],
                    even: true,
                    //skin: 'row',
                    checkbox: true,
                    field: 'id',
                    paged: true,
                    singleSelect: true,
                    params : packParams(),
                });
                btable.render();
                
                $('#updateButton').on('click', function () {
                    //获取选择的数据
                    btable.getSelections(function (obj) {
                    	if(obj.count == 0){
                    		layer.msg('请选择要修改的数据',{icon: 7,id : Math.ceil(100)});
                    	}else{
                    		layer.open({
                         		  type: 2,
                         		  title: false,
                         		  id : Math.ceil(100),
                         		  area: ['680px', '480px'],
                         		  closeBtn: 1,
                         		  content: '/fdoctor-ms/expert/toUpdateExpert?id='+obj.ids[0]
                          	});
                    	}
                    });

                });
                
                $('#detailButton').on('click', function () {
                    //获取选择的数据
                    btable.getSelections(function (obj) {
                    	if(obj.count == 0){
                    		layer.msg('请选择要查看详情的专家',{icon: 7,id : Math.ceil(100)});
                    	}else{
                    		layer.open({
                       		  type: 2,
                       		  title: false,
                       		  id : Math.ceil(100),
                       		  area: ['680px', '400px'],
                       		  closeBtn: 1,
                       		  content: '/fdoctor-ms/expert/getExpertbyId?id='+obj.ids[0]
                        	});
                    	}
                    });

                });
                
                $('#addButton').on('click', function () {
                	layer.open({
               		  type: 2,
               		  title: false,
               		  id : Math.ceil(100),
               		  area: ['680px', '500px'],
               		  closeBtn: 1,
               		  content: '/fdoctor-ms/expert/toAddExpert'
                	});
                });
                
                $('#deleteButton').on('click',function (){
                	 //获取选择的数据
                    btable.getSelections(function (obj) {
                    	if(obj.count == 0){
                    		layer.msg('请选择要删除的数据',{icon: 7,id : Math.ceil(100)});
                    	}else{
                    		layer.confirm('确认删除？', {icon: 3,id : Math.ceil(100)}, function(index){
                    			$.ajax({
            						type : 'POST',
            						url : '/fdoctor-ms/expert/deleteExpert',
            						data : {
            							id : obj.ids[0]
            						},
            						success : function(data) {
            							if (data.code == 200) {
            								layer.msg('删除成功！', {
            									icon : 1
            								});
            								tableConfig();
            							} else {
            								layer.msg('删除失败！', {
            									icon : 2
            								});
            							}
            						}
            					});
                   			});
                    	}
                    });
                });

               $(window).on('resize', function (e) {
                    var $that = $(this);
                    $('#content').height($that.height() - 92);
                }).resize();
                
            });
    		
    		
    	}
    	
    	tableConfig();
    
    	//查询按钮声明点击事件，查询逻辑
        $('#selectButton').on('click', function(){
        	tableConfig();
        });
  	  	
        function packParams(){
        	var orgId=$("#orgId").val();
        	if(orgId=='0'){
        		orgId='';
        	}
        	
    		var param = {
    				orgId:orgId,
    				expertName:$("#expertName").val()
    		}
    		return param;
    	}
        function typeRenderA(data){
        	if(data == '1'){
        		return '男';
        	}else if(data == '2'){
        		return '女';
        	}else{
        		return data;
        	}
        }
		function typeRenderB(data){
		    if(data==undefined){
		    	 return '';
		    }else if(data == '1'){
        		return '医生';
        	}else if(data == '2'){
        		return '公卫医生';
        	}else if(data == '3'){
        		return '护士';
        	}else{
        		return data;
        	}
        }
		function typeRenderC(data){
		    if(data == undefined ){
		    	return '';
		    }else if(data==null ||data==""){
		    	return '';
		    }else{
        		return data;
        	}
        }
		function typeRenderD(data){
			var org='${hospitalList2}';
			var orgList=$.parseJSON(org);
		    for(i=0;i<orgList.length;i++){
		    	if(data==orgList[i].id){
		    		return orgList[i].orgName;
		    	}
		    }
		    return data;
        }
    </script>
</body>
</html>